This is known as call-by-reference, because instead of passing a copy of a value to a function, I pass a pointer to that value instead, which means it can be accessed and modified by other functions.
Anyway, here is a very simple pass by reference in action:
#include <stdio.h>
#include <string.h>
char func(char *string);
int main(int argc, char* argv[]){
char* string;
string = "hello world";
func(string);
return 0;
}
char func(char* str){
printf("\nThe string came in as %s \n",str);
return 1;
}
of course if you compile and run this program, the output is as follows:
secondhalf-lm:junk clacy$ ./foo
The string came in as hello world
secondhalf-lm:junk clacy$
christo